import 'package:flutter/cupertino.dart';
import 'package:flutter_09_game/base/controller/base_controller.dart';
import 'package:flutter_09_game/config/app_routes.dart';
import 'package:flutter_09_game/http/http_export.dart';
import 'package:flutter_09_game/pages/promotion/promotion_withdraw/promotion_withdraw_logic.dart';
import 'package:flutter_09_game/user/app_user_manager.dart';
import 'package:flutter_09_game/utils/log/utils_log.dart';
import 'package:get/get.dart';

class ProfileBindAddressLogic extends BaseController {
  TextEditingController addressController = TextEditingController();
  RxBool isFormValid = false.obs;

  RxString fundPassword = ''.obs;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
    addressController.dispose();
  }

  /// 表单验证
  void validateForm() {
    final isValid =
        addressController.text.length > 10 && fundPassword.value.length == 6;
    isFormValid.value = isValid;
  }

  postUserBindTrc20Address() async {
    HttpResponse response =
        await HttpManager().post(API.postUserBindTrc20Address,
            // fromJson: .fromJson,
            params: {
              'address': addressController.text,
              'fund_password': fundPassword.value,
            },
            uiType: HttpUIType.loadingAndToast);
    if (response.isSuccess) {
      // return response.data;
      // Get.back();
      AppUserManager().refreshUserInfo();
      // if (Get.isRegistered<PromotionWithdrawLogic>()) {
        Get.back();
      // } else {
      //   Get.offAndToNamed(AppRoutes.profileTrcManagerPage);
      // }
    }
  }
}
